<!--
* @author wn
* @date 2022/04/24 11:16:10
* @description: 吸顶头部组件
!-->
<template>
	<div class="app-header-sticky" :class="{ show: y >= 78 }">
		<div class="container" v-show="y >= 78">
			<RouterLink class="logo" to="/" />
			<app-header-nav />
			<div class="right">
				<RouterLink to="/">品牌</RouterLink>
				<RouterLink to="/">专题</RouterLink>
			</div>
		</div>
	</div>
</template>
<script>
import AppHeaderNav from '@/components/AppHeaderNav'
// import { onMounted, ref } from 'vue'
import { useWindowScroll } from '@vueuse/core'
export default {
	name: 'AppHeaderSticky',
	components: {
		AppHeaderNav,
	},
	setup() {
		/*
  	// 记录 y轴 卷曲的高度
		const y = ref(0)
		// 页面滚动时更新 y
		onMounted(() => {
			window.onscroll = () => {
				const scrollTop = document.documentElement.scrollTop
				y.value = scrollTop
			}
		})
     */
		// 通过 vueuse 实现
		const { y } = useWindowScroll()
		return { y }
	},
}
</script>
<style scoped lang="less">
.app-header-sticky {
	position: fixed;
	left: 0;
	top: 0;
	width: 100%;
	height: 80px;
	background-color: #fff;
	border-bottom: 1px solid #e4e4e4;
	z-index: 999;
	// 初始移出 屏幕
	transform: translateY(-100%);
	opacity: 0;
	// 显示 吸顶
	&.show {
		transform: translateY(0);
		opacity: 1;
		transition: all 0.3s linear;
	}
	.container {
		display: flex;
		align-items: center;
		.logo {
			width: 200px;
			height: 80px;
			background: url(@/assets/images/logo.png) no-repeat right 2px / 160px auto;
		}
		.right {
			display: flex;
			width: 220px;
			text-align: center;
			padding-left: 40px;
			border-left: 2px solid @xtxColor;
			a {
				width: 38px;
				margin-right: 40px;
				font-size: 16px;
				// 为了 左侧竖线 根nav文字一样大
				line-height: 1;
				&:hover {
					color: @xtxColor;
				}
			}
		}
	}
}
</style>
